/// @tags:
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

namespace BlueQuantum {

int const N = 1 << 17, M = 1e4 + 5;
int n, m;
bitset<M> sum[N], tag[N >> 1], ans;

void modify(int x, int l, int r, int L, int R, int c) {
  sum[x][c] = true;
  if (L <= l && r <= R) {
    if (x < (1 << 16)) tag[x][c] = true;
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) modify(x << 1, l, mid, L, R, c);
  if (mid < R) modify(x << 1 | 1, mid + 1, r, L, R, c);
}

void query(int x, int l, int r, int L, int R) {
  if (x < (1 << 16)) ans |= tag[x];
  if (L <= l && r <= R) {
    ans |= sum[x];
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) query(x << 1, l, mid, L, R);
  if (mid < R) query(x << 1 | 1, mid + 1, r, L, R);
}

inline int main() {
  cin >> n >> m;
  for (int i = 1, opt, a, b, c; i <= m; ++i) {
    cin >> opt >> a >> b >> c;
    switch (opt) {
      case 1:
        modify(1, 1, n, a, b, c);
        break;
      case 2:
        ans.reset();
        query(1, 1, n, a, b);
        if (c == 0 || int(ans.count()) < c) {
          cout << "-1\n";
        } else {
          for (int i = 0; i < M; ++i) {
            if (ans[i]) --c;
            if (!c) {
              cout << i << '\n';
              break;
            }
          }
        }
    }
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("sset.in", "r", stdin);
  freopen("sset.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
